package com.bocai.yuweiwangluo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.View.RoundImageView;
import com.bocai.yuweiwangluo.bean.JoinPersonBean;
import com.bocai.yuweiwangluo.utils.ImageLoaderUtil;
import com.bocai.yuweiwangluo.utils.TimeUtils;
import com.bocai.yuweiwangluo.utils.UrlData;

/**
 * 应战者adapter
 */
public class ParticipantAdapter extends BaseAdapter{
    private Context context;
    private JoinPersonBean data;
    public ParticipantAdapter(Context context,JoinPersonBean data){
        this.context=context;
        this.data=data;
    }
    @Override
    public int getCount() {
        return data.getUsrs_join().size();
    }

    @Override
    public Object getItem(int position) {
        return data.getUsrs_join().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_participant_list,null);
            viewHolder.rivPhoto=(RoundImageView)convertView.findViewById(R.id.riv_participant_photo);
            viewHolder.tvName=(TextView)convertView.findViewById(R.id.tv_participant_name);
            viewHolder.tvTime= (TextView)convertView.findViewById(R.id.tv_participant_time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ImageLoaderUtil.loaderImageDefault(UrlData.IMAGEURL + data.getUsrs_join().get(position).getIcon(), viewHolder.rivPhoto);
        viewHolder.tvName.setText(data.getUsrs_join().get(position).getNickname()+"应战");
        if(data.getUsrs_join().get(position).getTimeline()!=null){
            viewHolder.tvTime.setText(TimeUtils.getTime_china(Long.parseLong(data.getUsrs_join().get(position).getTimeline())));
        }
        return convertView;
    }


    public class ViewHolder {
        RoundImageView rivPhoto;//应战者图像
        TextView tvName;//应战者名字
        TextView tvTime;//应战时间
    }
}
